package com.jincp.image.pick.bean;

import android.text.TextUtils;

import com.jincp.image.R;
import com.jincp.image.pick.Utils;

import java.io.File;


/**
 * Created by droidNinja on 29/07/16.
 */
public class Document extends BaseFile{

    public interface FILE_TYPE {
        int PDF = 0x001;
        int WORD = 0x002;
        int EXCEL = 0x003;
        int PPT = 0x004;
        int TXT = 0x005;
        int UNKNOWN = 0x006;
    }

    public String mimeType;
    public boolean isSelected;

    public Document(int id, String title, String path, long size) {
        super(id, title, path, size);
    }

    public String getTitle() {
        return new File(this.path).getName();
    }

    public void setTitle(String title) {
        this.name = title;
    }

    public int getTypeDrawable() {
        if (getFileType() == FILE_TYPE.EXCEL)
            return R.drawable.ic_xls;
        if (getFileType() == FILE_TYPE.WORD)
            return R.drawable.ic_doc;
        if (getFileType() == FILE_TYPE.PPT)
            return R.drawable.icon_ppt;
        if (getFileType() == FILE_TYPE.PDF)
            return R.drawable.ic_pdf;
        if (getFileType() == FILE_TYPE.TXT)
            return R.drawable.ic_txt;
        else
            return R.drawable.ic_doc;
    }

    public boolean isThisType(int type) {
        if (getFileType() == type)
            return true;

        return false;
    }

    public int getFileType() {
        String fileExtension = Utils.getFileExtension(new File(this.path));
        if (TextUtils.isEmpty(fileExtension))
            return FILE_TYPE.UNKNOWN;

        if (isExcelFile())
            return FILE_TYPE.EXCEL;
        if (isDocFile())
            return FILE_TYPE.WORD;
        if (isPPTFile())
            return FILE_TYPE.PPT;
        if (isPDFFile())
            return FILE_TYPE.PDF;
        if (isTxtFile())
            return FILE_TYPE.TXT;
        else
            return FILE_TYPE.UNKNOWN;
    }

    public boolean isExcelFile() {
        String[] types = {"xls", "xlsx"};
        return Utils.contains(types, this.path);
    }

    public boolean isDocFile() {
        String[] types = {"doc", "docx", "dot", "dotx"};
        return Utils.contains(types, this.path);
    }

    public boolean isPPTFile() {
        String[] types = {"ppt", "pptx"};
        return Utils.contains(types, this.path);
    }

    public boolean isPDFFile() {
        String[] types = {"pdf"};
        return Utils.contains(types, this.path);
    }

    public boolean isTxtFile() {
        String[] types = {"txt"};
        return Utils.contains(types, this.path);
    }

}
